 <?php
	require_once('db_connect.php');
	require_once('distance.php');
	
	$user_id = $_GET['user_id']; // 창천동 등 지역명
	$lat = $_GET['lat'];
	$lng = $_GET['lng'];
	$radius = $_GET['radius'];
	
	$query = "select * from session where user_id <> '$user_id'";
	$data = mysqli_query($conn, $query)
		or die('session 가져오는 쿼리 실패');

	$adjacency_users = array();
	while ($row = mysqli_fetch_array($data)) {
		if (distance($lat, $lng, doubleval($row['lat']), doubleval($row['lng'])) <= doubleval($radius)) {
			$query = "select facebook_id from preset where user_id='$row[user_id]'";
			$data2 = mysqli_query($conn, $query)
				or die('preset 가져오는 쿼리 실패');
			
			if (mysqli_num_rows($data2) <= 0)
				continue;
			
			$row2 = mysqli_fetch_array($data2);
			$a_adj_user = array('fb_id' => $row2['facebook_id'], 'lat' => $row['lat'], 'lng' => $row['lng']);
			array_push($adjacency_users, $a_adj_user);
		}
	}
	mysqli_close($conn);
	echo json_encode($adjacency_users);
?>